//
//  FDMTopRadioListCollectionViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/22.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMTopRadioListCollectionViewCell.h"
#import "FDMTopRadioDataModel.h"
#import "FDMTopRadioDetailModel.h"

@interface FDMTopRadioListCollectionViewCell ()

@property (nonatomic, retain) UIImageView *titleImage;
@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) FDMBaseLabel *firstListLabel;
@property (nonatomic, retain) FDMBaseLabel *secondListLabel;
@property (nonatomic, retain) UIImageView *nextImageView;

@end
@implementation FDMTopRadioListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)dealloc {
    [self.titleImage release];
    [self.titleLabel release];
    [self.firstListLabel release];
    [self.secondListLabel release];
    [self.nextImageView release];
    [super dealloc];
}

- (void)createCell {
    self.titleImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleImage];
    [self.titleImage release];
    self.titleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    self.firstListLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.firstListLabel];
    [self.firstListLabel release];
    self.secondListLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.secondListLabel];
    [self.secondListLabel release];
    self.nextImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.nextImageView];
    [self.nextImageView release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.width.mas_equalTo(@100);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_top).with.offset(20);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 160));
    }];
    self.firstListLabel.font = [UIFont systemFontOfSize:14];
    self.firstListLabel.textColor = [UIColor grayColor];
    [self.firstListLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-40);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-20);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 160));
    }];
    self.secondListLabel.font = [UIFont systemFontOfSize:14];
    self.secondListLabel.textColor = [UIColor grayColor];
    [self.secondListLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.firstListLabel.mas_bottom).with.offset(0);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-20);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 160));
    }];
    self.nextImageView.image = [UIImage imageNamed:@"xm_accessory@2x.png"];
    [self.nextImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(-CONTENTVIEW_HEIGHT / 2 - 10);
        make.left.equalTo(self.contentView.mas_right).with.offset(-30);
        make.right.equalTo(self.contentView.mas_right).with.offset(-10);
        make.height.mas_equalTo(@20);
    }];
    
}

- (void)setDataModel:(FDMTopRadioDataModel *)dataModel {
    if (_dataModel != dataModel) {
        [_dataModel release];
        _dataModel = [dataModel retain];
       
    }
}

- (void)setDetailModel:(FDMTopRadioDetailModel *)detailModel {
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = [detailModel retain];
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_detailModel.coverPath] placeholderImage:PLACEHOLDER_IMAGE];
        self.titleLabel.text = _detailModel.title;
        self.firstListLabel.text = [NSString stringWithFormat:@"1. %@", _detailModel.firstKResults];
        self.secondListLabel.text = [NSString stringWithFormat:@"2. %@",_detailModel.secondKResults];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
